/*
 * Air Roommates Accounts
 *Copyright 2009 - Julien EVANO & Enguerran GILLET
 *
 *This program is free software: you can redistribute it and/or modify
 *it under the terms of the GNU General Public License as published by
 *the Free Software Foundation, either version 3 of the License, or
 *(at your option) any later version.
 *
 *This program is distributed in the hope that it will be useful,
 *but WITHOUT ANY WARRANTY; without even the implied warranty of
 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *GNU General Public License for more details.
 *
 *You should have received a copy of the GNU General Public License
 *along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *Distributed under the terms of the GNU GPL v3.
 *http://www.gnu.org/licenses/gpl-3.0.html
 */

/** Initialize the state provider */
air.trace('Ext.state.Manager.setProvider');
Ext.state.Manager.setProvider(new Ext.air.FileProvider( {
	file :'airroommatesaccounts.state',
	// if first time running
	defaultState : {
		mainWindow : {
			width :780,
			height :580,
			x :10,
			y :10
		},
		defaultReminder :480
	}
}));

/** Initialize the application */
Ext.onReady( function() {
	
	Ext.QuickTips.init();
	
	/** Air Native Window */
	air.trace('Air Native Window');
	var win = new Ext.air.NativeWindow( {
		id :'mainWindow',
		instance :window.nativeWindow,
		minimizeToTray :true,
		trayIcon :'resources/extjs/air/icons/extlogo16.png',
		trayTip :'Air Roommates Accounts',
		trayMenu : [ {
			text :'Open Air Roommates Accounts',
			handler : function() {
				win.activate();
			}
		}, '-', {
			text :'Exit',
			handler : function() {
				air.NativeApplication.nativeApplication.exit();
			}
		} ]
	});
	
	/** Open Database Connection */
	air.trace('Open Database Connection');
	ARA.data.conn.open('database/air-roommates-accounts.sqlite');

	/** System menu */
	air.trace('System menu');
	var menus = Ext.air.SystemMenu;
	menus.add('File', [ ARA.actions.newEntry, ARA.actions.newGroup, ARA.actions.newProfil, '-', ARA.actions.quit ]);
	menus.add('Help', [ {
		text :'About',
		handler : function() {
			Ext.air.NativeWindowManager.getAboutWindow().activate();
		}
	} ]);

	/** North - Toolbar */
	air.trace('Toolbar');
	var tb = {
		region: 'north',
		html: 'toolbar'
	};
	
	/** West - Tree Tabs */
	air.trace('Tree Tabs');
	var treeTabs = {
		region: 'west',
		html: 'trees'
	};

	/** Center - Grip */
	air.trace('Grid');
	var grid = new ARA.viewport.center.EntriesGrid();
	
	/** Viewport */
	air.trace('Viewport');
	var viewport = new Ext.Viewport({
        layout:'border',
        items: [tb, treeTabs, grid]
    });
	
	/** Air Native Window Opening */
	air.trace('Air Native Window Opening');
	win.show();
	win.instance.activate();
	win.on('closing', function() {
		Ext.air.NativeWindowManager.closeAll();
	});
});
